package utils;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class TimeUtil {

    private static final DateTimeFormatter MYSQL_DATETIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    /**
     * 将 LocalDateTime 转换为 MySQL datetime 格式的字符串
     *
     * @param localDateTime 要转换的 LocalDateTime 对象
     * @return MySQL datetime 格式的字符串
     */
    public static String localDateTimeToMysqlFormat(LocalDateTime localDateTime) {
        if (localDateTime == null) {
            return null;
        }
        return localDateTime.format(MYSQL_DATETIME_FORMATTER);
    }
}
